package com.zoke.support.image;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.zoke.support.R;
import com.zoke.support.base.BaseObjectListAdapter;
import com.zoke.support.image.activity.GalleryActivity;
import com.zoke.support.image.activity.ShowImagesActivity;
import com.zoke.support.utils.LogUtil;
import com.zoke.support.utils.ViewHolder;
import com.zoke.support.view.ZokeRelativeLayout;
import com.zoke.support.view.ZokeTextView;

/**
 * 相册分组
 * 
 * @author JackWu
 * @version
 * @date 2014-2-17
 * @_QQ_ 651319154
 */
public class ImageGroupsAdapter extends BaseObjectListAdapter {

	private ZokeRelativeLayout mItemContainer;
	private ThumbnailImageView mImageIv;
	private ZokeTextView mTitleTv;
	private ZokeTextView mGroupCountTv;
	private HashMap<String, List<String>> mGruopMap;
	private int mType;

	public ImageGroupsAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
	}

	public ImageGroupsAdapter(Context context, List<? extends Object> datas,
			HashMap<String, List<String>> mGruopMap, int type) {
		super(context, datas);
		this.mGruopMap = mGruopMap;
		this.mType = type;
	}

	@Override
	public View getItemView(int position, View convertView, ViewGroup parent) {
		convertView = getConvertView(convertView,
				R.layout.listview_item_imagegroups);
		final ImageBean imageBeen = (ImageBean) mDatas.get(position);
		mItemContainer = ViewHolder.get(convertView,
				R.id.photots_item_container);
		mImageIv = ViewHolder.get(convertView, R.id.group_image);
		mTitleTv = ViewHolder.get(convertView, R.id.group_title);
		mGroupCountTv = ViewHolder.get(convertView, R.id.group_count);
		mTitleTv.setText(imageBeen.getFolderName());
		mGroupCountTv.setText("("
				+ Integer.toString(imageBeen.getImageCounts()) + ")");
		String uri = "file:///" + imageBeen.getTopImagePath();
		LogUtil.i("处理图片--" + uri);
		ImageLoader.getInstance().displayImage(uri, mImageIv,
				ImageOptions.getThumbOptions());
		mItemContainer.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				List<String> childList = mGruopMap.get(imageBeen
						.getFolderName());
				Intent intent = new Intent(mContext, ShowImagesActivity.class);
				intent.putExtra(
						ShowImagesActivity.PHOTOSFIRSNAME,
						imageBeen.getFolderName() + "("
								+ Integer.toString(imageBeen.getImageCounts())
								+ ")");
				intent.putStringArrayListExtra(
						ShowImagesActivity.PHOTOSDATASSTRINGS,
						(ArrayList<String>) childList);
				// 将外部的操作需求发出给相册列表
				intent.putExtra(GalleryActivity.HANDLETYPE, mType);
				startUI(intent);
			}
		});
		return convertView;
	}

}
